﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;

namespace CPN.PJN.Silverlight.Extensions.Converters
{
    /// <summary>
    /// Converter permettant de récupérer la valeur d'un Dictionary d'après sa clef passée en paramètre
    /// </summary>
    public class DictionaryValueConverter : IValueConverter
    {
        public object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                IDictionary<Object, Object> dictionary = parameter as IDictionary<Object, Object>;
                if (dictionary != null)
                {
                    return dictionary[value.ToString()];
                }
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, Object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
